home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / bindings / fun2ref < prev    next >
Encoding:
Text File  |  1996-09-27  |  3.9 KB  |  195 lines

  1. #!/bin/sh
  2.  
  3. AWK_FILE="/tmp/ref.tmp.awk"
  4.  
  5. trap "/bin/rm -r -f $AWK_FILE" 0 1 2 3 15
  6.  
  7. #{{{}}}
  8. #{{{  -d -> gen dependencies
  9. if test x$1 = x-d
  10. then
  11.    shift
  12.    AWK=$1
  13.    shift
  14. #{{{  gen awk script
  15. cat >$AWK_FILE <<\HERE
  16.    BEGIN {
  17.       fr="\nFUNREF="
  18.    }
  19.    /^ *@if-using *\( *FUN-REFERENCE *\)/ {
  20.       if (u[FILENAME]==0) {
  21.          u[FILENAME]=1;
  22.          fr=fr"\\\n "FILENAME".r";
  23.          d=d"\n"FILENAME".r: "FILENAME;
  24.       }
  25.    }
  26.    END {
  27.       print fr;
  28.       print d;
  29.    }
  30. HERE
  31. #}}}
  32.    ( echo "# automatically generated dependency file"
  33.      $AWK -f $AWK_FILE $@
  34.    ) >dependencies
  35.    exit 0
  36. fi
  37. #}}}
  38. #{{{  -r -> gen references
  39. if test x$1 = x-r
  40. then
  41.    shift
  42.    AWK=$1
  43.    shift
  44. #{{{  gen awk script
  45. cat >$AWK_FILE <<\HERE
  46. #{{{  init: not text written, no chapters seen, predefined chapter names
  47. BEGIN {
  48.    if_depth=0
  49.    chapters=0
  50.    handle=""
  51.    chap_name["1"]="Description"
  52.    chap_name["2"]="Functions and macros"
  53.    chap_name["3"]="Hooks"
  54.    chap_name["4"]="Libraries"
  55.    chap_name["5"]="Bugs and limitations"
  56.    libs=""
  57. }
  58. #}}}
  59. #{{{  set filename
  60. name=="" {
  61.    name=FILENAME
  62.    for (i=1;i<=length(name);)
  63.       if (substr(name,i,1)=="/") {
  64.          name=substr(name,i+1)
  65.          i=1
  66.       } else
  67.          i=i+1
  68. }
  69. #}}}
  70. #{{{  store lib
  71. /^ *@lib +[^ ]*$/ {
  72.    if (lib_used[$2]==0) {
  73.       lib_used[$2]=1
  74.       if (libs=="")
  75.          libs="      The library '"name"' uses the libraries:\n"
  76.       libs=libs"         '"$2"'\n"
  77.    }
  78. }
  79. #}}}
  80. #{{{  start pattern found, set handling to TRUE, store destination chapter
  81. /^ *@if-using +\( +FUN-REFERENCE +\) +;( +[^ ]+)+ +;( +[^ ]+)* *$/ {
  82. #   {{{  get chapter name
  83.    handle=$6
  84.    for (i=7;i<=NF && $i!=";";i++)
  85.       handle=handle" "$i
  86.    if (chap_name[handle]=="")
  87.       chap_name[handle]=handle
  88.    else
  89.       handle=chap_name[handle]
  90.    if (defined[handle]=="") {
  91.       defined[handle]="@"
  92.       tags[handle]=" complete"
  93.       chapter[chapters++]=handle
  94.    }
  95. #   }}}
  96. #   {{{  get if-using tags for this entry
  97.    text[handle]=text[handle]"@if-using ( complete"
  98.    for (i++;i<=NF;i++) {
  99.       tags[handle]=tags[handle]" "$i
  100.       text[handle]=text[handle]" "$i
  101.    }
  102.    text[handle]=text[handle]" )\n"
  103. #   }}}
  104. #   {{{  get indentation
  105.    skip_txt=""
  106.    skip_len=0
  107.    while(substr($0,skip_len+1,1)==" ") {
  108.       skip_len++
  109.       skip_txt=skip_txt" "
  110.    }
  111. #   }}}
  112.    if_depth=1
  113.    next
  114. }
  115. #}}}
  116. #{{{  handling FALSE -> next
  117. if_depth==0 {
  118.    next
  119. }
  120. #}}}
  121. #{{{  handle depth of if-usings, maybe end handling
  122. /^ *@ *if-using/ {
  123.    if_depth++
  124. }
  125. /^ *@ *fi/ {
  126.    if_depth--
  127. }
  128. if_depth==0 {
  129.    text[handle]=text[handle]"@fi\n"
  130.    handle=""
  131.    next
  132. }
  133. handle=="" {
  134.    next
  135. }
  136. #}}}
  137. #{{{  check indentation of reference line
  138. $0!="" && skip_txt!=substr($0,1,skip_len) {
  139.    print("@error incorrect indentation of reference-source (need indentation "skip_len"!")
  140.    exit
  141. }
  142. #}}}
  143. #{{{  store text to wished chapter
  144. /^ *;OCL\{\{\{  @/ {
  145.    text[handle]=text[handle]"@{{{  "substr($0,10+skip_len)"\n"
  146.    next
  147. }
  148. /^ *;OCL\{\{\{/ {
  149.    text[handle]=text[handle]"@{{{  @"name"-ref "substr($0,10+skip_len)"\n"
  150.    next
  151. }
  152. /^ *;OCL\}\}\}/ {
  153.    text[handle]=text[handle]"@"substr($0,5+skip_len)"\n"
  154.    next
  155. }
  156. {  text[handle]=text[handle] substr($0,skip_len+1)"\n"
  157.    next
  158. }
  159. #}}}
  160. #{{{  end: print all stored text/chapters
  161. END {
  162.    if (libs!="" && defined[chap_name[4]]=="") {
  163.       tags[chap_name[4]]=" complete"
  164.       chapter[chapters++]=chap_name[4]
  165.       text[chap_name[4]]=libs
  166.    }
  167.    print("@ref-see-also See also in %s.")
  168.    print("@{{{}}}");
  169.    print("@{{{  "name"-reference-file")
  170.    for (i=0;i<chapters;i++) {
  171.        if (tags[chapter[i]]!="")
  172.           print("@if-using ("tags[chapter[i]]" )")
  173.        print("@{{{  @"name"-ref "chapter[i])
  174.        printf("%s",text[chapter[i]])
  175.        print("@}}}")
  176.        if (tags[chapter[i]]!="")
  177.           print("@fi")
  178.    }
  179.    print("@}}}")
  180. }
  181. #}}}
  182. HERE
  183. #}}}
  184.    $AWK -f $AWK_FILE $@
  185.    exit 0
  186. fi
  187. #}}}
  188. #{{{  show help
  189. echo "USAGE:"
  190. echo "    fun2ref -[dr] awk files"
  191. echo "where:"
  192. echo "    -d generates dependencies"
  193. echo "    -r extracts the reference data from library files"
  194. #}}}
  195.